// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.MachineLearning;

public sealed partial class DataframePreviewConfig
{
	[JsonInclude, JsonPropertyName("analysis")]
	public Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysis Analysis { get; set; }
	[JsonInclude, JsonPropertyName("analyzed_fields")]
	public Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisAnalyzedFields? AnalyzedFields { get; set; }
	[JsonInclude, JsonPropertyName("max_num_threads")]
	public int? MaxNumThreads { get; set; }
	[JsonInclude, JsonPropertyName("model_memory_limit")]
	public string? ModelMemoryLimit { get; set; }
	[JsonInclude, JsonPropertyName("source")]
	public Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalyticsSource Source { get; set; }
}

public sealed partial class DataframePreviewConfigDescriptor<TDocument> : SerializableDescriptor<DataframePreviewConfigDescriptor<TDocument>>
{
	internal DataframePreviewConfigDescriptor(Action<DataframePreviewConfigDescriptor<TDocument>> configure) => configure.Invoke(this);

	public DataframePreviewConfigDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysis AnalysisValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisDescriptor<TDocument> AnalysisDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisDescriptor<TDocument>> AnalysisDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisAnalyzedFields? AnalyzedFieldsValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisAnalyzedFieldsDescriptor AnalyzedFieldsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisAnalyzedFieldsDescriptor> AnalyzedFieldsDescriptorAction { get; set; }
	private int? MaxNumThreadsValue { get; set; }
	private string? ModelMemoryLimitValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalyticsSource SourceValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalyticsSourceDescriptor<TDocument> SourceDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalyticsSourceDescriptor<TDocument>> SourceDescriptorAction { get; set; }

	public DataframePreviewConfigDescriptor<TDocument> Analysis(Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysis analysis)
	{
		AnalysisDescriptor = null;
		AnalysisDescriptorAction = null;
		AnalysisValue = analysis;
		return Self;
	}

	public DataframePreviewConfigDescriptor<TDocument> Analysis(Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisDescriptor<TDocument> descriptor)
	{
		AnalysisValue = null;
		AnalysisDescriptorAction = null;
		AnalysisDescriptor = descriptor;
		return Self;
	}

	public DataframePreviewConfigDescriptor<TDocument> Analysis(Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisDescriptor<TDocument>> configure)
	{
		AnalysisValue = null;
		AnalysisDescriptor = null;
		AnalysisDescriptorAction = configure;
		return Self;
	}

	public DataframePreviewConfigDescriptor<TDocument> AnalyzedFields(Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisAnalyzedFields? analyzedFields)
	{
		AnalyzedFieldsDescriptor = null;
		AnalyzedFieldsDescriptorAction = null;
		AnalyzedFieldsValue = analyzedFields;
		return Self;
	}

	public DataframePreviewConfigDescriptor<TDocument> AnalyzedFields(Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisAnalyzedFieldsDescriptor descriptor)
	{
		AnalyzedFieldsValue = null;
		AnalyzedFieldsDescriptorAction = null;
		AnalyzedFieldsDescriptor = descriptor;
		return Self;
	}

	public DataframePreviewConfigDescriptor<TDocument> AnalyzedFields(Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisAnalyzedFieldsDescriptor> configure)
	{
		AnalyzedFieldsValue = null;
		AnalyzedFieldsDescriptor = null;
		AnalyzedFieldsDescriptorAction = configure;
		return Self;
	}

	public DataframePreviewConfigDescriptor<TDocument> MaxNumThreads(int? maxNumThreads)
	{
		MaxNumThreadsValue = maxNumThreads;
		return Self;
	}

	public DataframePreviewConfigDescriptor<TDocument> ModelMemoryLimit(string? modelMemoryLimit)
	{
		ModelMemoryLimitValue = modelMemoryLimit;
		return Self;
	}

	public DataframePreviewConfigDescriptor<TDocument> Source(Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalyticsSource source)
	{
		SourceDescriptor = null;
		SourceDescriptorAction = null;
		SourceValue = source;
		return Self;
	}

	public DataframePreviewConfigDescriptor<TDocument> Source(Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalyticsSourceDescriptor<TDocument> descriptor)
	{
		SourceValue = null;
		SourceDescriptorAction = null;
		SourceDescriptor = descriptor;
		return Self;
	}

	public DataframePreviewConfigDescriptor<TDocument> Source(Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalyticsSourceDescriptor<TDocument>> configure)
	{
		SourceValue = null;
		SourceDescriptor = null;
		SourceDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (AnalysisDescriptor is not null)
		{
			writer.WritePropertyName("analysis");
			JsonSerializer.Serialize(writer, AnalysisDescriptor, options);
		}
		else if (AnalysisDescriptorAction is not null)
		{
			writer.WritePropertyName("analysis");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisDescriptor<TDocument>(AnalysisDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("analysis");
			JsonSerializer.Serialize(writer, AnalysisValue, options);
		}

		if (AnalyzedFieldsDescriptor is not null)
		{
			writer.WritePropertyName("analyzed_fields");
			JsonSerializer.Serialize(writer, AnalyzedFieldsDescriptor, options);
		}
		else if (AnalyzedFieldsDescriptorAction is not null)
		{
			writer.WritePropertyName("analyzed_fields");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisAnalyzedFieldsDescriptor(AnalyzedFieldsDescriptorAction), options);
		}
		else if (AnalyzedFieldsValue is not null)
		{
			writer.WritePropertyName("analyzed_fields");
			JsonSerializer.Serialize(writer, AnalyzedFieldsValue, options);
		}

		if (MaxNumThreadsValue.HasValue)
		{
			writer.WritePropertyName("max_num_threads");
			writer.WriteNumberValue(MaxNumThreadsValue.Value);
		}

		if (!string.IsNullOrEmpty(ModelMemoryLimitValue))
		{
			writer.WritePropertyName("model_memory_limit");
			writer.WriteStringValue(ModelMemoryLimitValue);
		}

		if (SourceDescriptor is not null)
		{
			writer.WritePropertyName("source");
			JsonSerializer.Serialize(writer, SourceDescriptor, options);
		}
		else if (SourceDescriptorAction is not null)
		{
			writer.WritePropertyName("source");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalyticsSourceDescriptor<TDocument>(SourceDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("source");
			JsonSerializer.Serialize(writer, SourceValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class DataframePreviewConfigDescriptor : SerializableDescriptor<DataframePreviewConfigDescriptor>
{
	internal DataframePreviewConfigDescriptor(Action<DataframePreviewConfigDescriptor> configure) => configure.Invoke(this);

	public DataframePreviewConfigDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysis AnalysisValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisDescriptor AnalysisDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisDescriptor> AnalysisDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisAnalyzedFields? AnalyzedFieldsValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisAnalyzedFieldsDescriptor AnalyzedFieldsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisAnalyzedFieldsDescriptor> AnalyzedFieldsDescriptorAction { get; set; }
	private int? MaxNumThreadsValue { get; set; }
	private string? ModelMemoryLimitValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalyticsSource SourceValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalyticsSourceDescriptor SourceDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalyticsSourceDescriptor> SourceDescriptorAction { get; set; }

	public DataframePreviewConfigDescriptor Analysis(Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysis analysis)
	{
		AnalysisDescriptor = null;
		AnalysisDescriptorAction = null;
		AnalysisValue = analysis;
		return Self;
	}

	public DataframePreviewConfigDescriptor Analysis(Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisDescriptor descriptor)
	{
		AnalysisValue = null;
		AnalysisDescriptorAction = null;
		AnalysisDescriptor = descriptor;
		return Self;
	}

	public DataframePreviewConfigDescriptor Analysis(Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisDescriptor> configure)
	{
		AnalysisValue = null;
		AnalysisDescriptor = null;
		AnalysisDescriptorAction = configure;
		return Self;
	}

	public DataframePreviewConfigDescriptor AnalyzedFields(Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisAnalyzedFields? analyzedFields)
	{
		AnalyzedFieldsDescriptor = null;
		AnalyzedFieldsDescriptorAction = null;
		AnalyzedFieldsValue = analyzedFields;
		return Self;
	}

	public DataframePreviewConfigDescriptor AnalyzedFields(Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisAnalyzedFieldsDescriptor descriptor)
	{
		AnalyzedFieldsValue = null;
		AnalyzedFieldsDescriptorAction = null;
		AnalyzedFieldsDescriptor = descriptor;
		return Self;
	}

	public DataframePreviewConfigDescriptor AnalyzedFields(Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisAnalyzedFieldsDescriptor> configure)
	{
		AnalyzedFieldsValue = null;
		AnalyzedFieldsDescriptor = null;
		AnalyzedFieldsDescriptorAction = configure;
		return Self;
	}

	public DataframePreviewConfigDescriptor MaxNumThreads(int? maxNumThreads)
	{
		MaxNumThreadsValue = maxNumThreads;
		return Self;
	}

	public DataframePreviewConfigDescriptor ModelMemoryLimit(string? modelMemoryLimit)
	{
		ModelMemoryLimitValue = modelMemoryLimit;
		return Self;
	}

	public DataframePreviewConfigDescriptor Source(Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalyticsSource source)
	{
		SourceDescriptor = null;
		SourceDescriptorAction = null;
		SourceValue = source;
		return Self;
	}

	public DataframePreviewConfigDescriptor Source(Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalyticsSourceDescriptor descriptor)
	{
		SourceValue = null;
		SourceDescriptorAction = null;
		SourceDescriptor = descriptor;
		return Self;
	}

	public DataframePreviewConfigDescriptor Source(Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalyticsSourceDescriptor> configure)
	{
		SourceValue = null;
		SourceDescriptor = null;
		SourceDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (AnalysisDescriptor is not null)
		{
			writer.WritePropertyName("analysis");
			JsonSerializer.Serialize(writer, AnalysisDescriptor, options);
		}
		else if (AnalysisDescriptorAction is not null)
		{
			writer.WritePropertyName("analysis");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisDescriptor(AnalysisDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("analysis");
			JsonSerializer.Serialize(writer, AnalysisValue, options);
		}

		if (AnalyzedFieldsDescriptor is not null)
		{
			writer.WritePropertyName("analyzed_fields");
			JsonSerializer.Serialize(writer, AnalyzedFieldsDescriptor, options);
		}
		else if (AnalyzedFieldsDescriptorAction is not null)
		{
			writer.WritePropertyName("analyzed_fields");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalysisAnalyzedFieldsDescriptor(AnalyzedFieldsDescriptorAction), options);
		}
		else if (AnalyzedFieldsValue is not null)
		{
			writer.WritePropertyName("analyzed_fields");
			JsonSerializer.Serialize(writer, AnalyzedFieldsValue, options);
		}

		if (MaxNumThreadsValue.HasValue)
		{
			writer.WritePropertyName("max_num_threads");
			writer.WriteNumberValue(MaxNumThreadsValue.Value);
		}

		if (!string.IsNullOrEmpty(ModelMemoryLimitValue))
		{
			writer.WritePropertyName("model_memory_limit");
			writer.WriteStringValue(ModelMemoryLimitValue);
		}

		if (SourceDescriptor is not null)
		{
			writer.WritePropertyName("source");
			JsonSerializer.Serialize(writer, SourceDescriptor, options);
		}
		else if (SourceDescriptorAction is not null)
		{
			writer.WritePropertyName("source");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.DataframeAnalyticsSourceDescriptor(SourceDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("source");
			JsonSerializer.Serialize(writer, SourceValue, options);
		}

		writer.WriteEndObject();
	}
}